package com.xlh.server.protocol.support.json;

import android.view.View;

import com.xlh.Utils.Constant;
import com.xlh.Utils.GsonManager;
import com.xlh.Utils.MudProtocol;
import com.xlh.bean.ProtocolObject.Base;
import com.xlh.bean.ProtocolObject.RoomObject;
import com.xlh.bean.ProtocolObject.Window;
import com.xlh.bean.TitleBean;
import com.xlh.interf.IActivity;
import com.xlh.interf.ITakeMessage;
import com.xlh.outside.MainActivity;

import net.nightwhistler.htmlspanner.HtmlSpanner;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/2.
 */

public class RoomObjectServer implements ITakeMessage {

    private IActivity atv;
    private String hasType = "roomObject";
    private RoomObject protccoObj;
    public RoomObjectServer(IActivity atv){
        this.atv = atv;
    }

    @Override
    public void takeMessage(String t,String s){

        if(!t.equals(this.hasType)) return;

        protccoObj =  GsonManager.gsmgr.jsonToAnyObject(s, RoomObject.class);

        if( protccoObj==null || protccoObj.getObjects()==null) return;

        List<TitleBean> data = new ArrayList<TitleBean>();
        data.clear();

        for (int i = 0; i < protccoObj.getObjects().size(); i++) {

            TitleBean but = new TitleBean();

            but.setSpanned(this.atv.getActivity().getHtmlSpanner().fromHtml(protccoObj.getObjects().get(i).getObjectTitle()));
            but.setmAction(protccoObj.getObjects().get(i).getObjectFile());
            data.add(but);
        }
        this.atv.getActivity().mTitleAdapter.addTitle(data);


    }

    @Override
    public boolean takeMessage(String s) {
        return false;
    }

    @Override
    public void init() {

    }

    @Override
    public void atViewLoadAfterInit(){



    }





}
